import prettier from 'prettier/standalone'
import parserBabel from 'prettier/plugins/babel'
import parserEstree from 'prettier/plugins/estree'

export async function formatCode(code: string, language: 'json' | 'javascript' = 'json') {
  const parser = language === 'json' ? 'json' : 'babel'

  return prettier.format(code, {
    parser,
    plugins: [parserBabel, parserEstree],
    tabWidth: 2,
    semi: true,
    singleQuote: true
  })
}